package draw;

import edit.DrawPolygonContext;

import java.util.List;
import java.awt.*;

import org.jbox2d.common.Vec2;

/**
 * @author will
 * @date Aug 9, 2008 10:26:22 PM
 */
public class DrawPolygonSprite extends DrawSprite {

    public DrawPolygonSprite(DrawPolygonContext ed) {
        super(ed);
    }

    protected void draw(Graphics2D g) {
        List<Vec2> vec2s = ((DrawPolygonContext) ed).points;
        int nPoints = vec2s.size() + 1;
        int[] xPoints = new int[nPoints];
        int[] yPoints = new int[nPoints];
        for(int i=0;i<nPoints-1;i++) {
            Vec2 vec = layer.getCanvasVector(vec2s.get(i));
            xPoints[i] = (int)vec.x;
            yPoints[i] = (int)vec.y;
        }
        Vec2 mouse = layer.getCanvasVector(ed.mousePos);
        xPoints[nPoints-1] = (int)mouse.x;
        yPoints[nPoints-1] = (int)mouse.y;
        g.setColor(Color.green);
        g.drawPolygon(xPoints,yPoints,nPoints);
    }

}
